package com.syn.synold4s.control;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;

import com.gaoyi.basemodule.baseControl.BaseView;
import com.syn.synold4s.databinding.GassItemBinding;

public class GassItem extends BaseView<GassItemBinding> {

    public GassItem(@NonNull Context context) {
        super(context);
    }

    public GassItem(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void initView(TypedArray ta) {
    }

    /**
     * 上方值
     */
    public void setValue(String val, String code) {
        if (TextUtils.isEmpty(val)) {
            mBinding.tvGassValue.setText("--");
            return;
        }
        String unit = "%";
        if (code.equals("CO") || code.equals("H2S")) {
            unit = "ppm";
        } else if (code.equals("WL")) {
            unit = "m";
        }
        val += unit;
        mBinding.tvGassValue.setText(val);
    }

    /**
     * 下方时间
     */
    public void setTime(String data) {
        mBinding.tvGassTime.setText(data != null ? data : "");
    }

    @Override
    protected GassItemBinding getViewBinding() {
        return GassItemBinding.inflate(LayoutInflater.from(mContext));
    }

    @Override
    protected int[] getAttrs() {
        return new int[]{};
    }
}
